﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace LPV_POS.mh_pos.mh_cauhinh
{
    public partial class mh_dm_mayin_R : DevExpress.XtraEditors.XtraForm
    {

        public mh_dm_mayin_R()
        {
            InitializeComponent();
        }

        private void mh_dm_mayin_bep_Load(object sender, EventArgs e)
        {
            this.showData_BEP_MayIn();
            this.showData_BEP_CauHinh();
            //
            this.showData_HoaDon_MayIn();
            this.showData_HoaDon_CauHinh();
            //
            this.showData_BIENNHAN_MayIn();
            this.showData_BIENNHAN_CauHinh();
        }

        #region "   BEP" 
        private void simpleButton5_Click(object sender, EventArgs e)
        {
            //them            
            this.ShowEdit_BEP("-1");
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            ma = dr["DM_MAYIN_BEP_MA"] + "";

            if (ma != "") 
            {
                if (new mh_thongbao("Bạn muốn xóa", 4).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_BEP WHERE DM_MAYIN_BEP_MA=" + ma;
                    int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });

                    this.showData_BEP_MayIn();
                }
            }
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            ma = dr["DM_MAYIN_BEP_MA"] + "";
            this.ShowEdit_BEP(ma);
        }

        void showData_BEP_MayIn()
        { 
            thuvien othuvien = new  thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BEP";

            DataTable tbInBep = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControl_Bep.DataSource = tbInBep.Copy();

            

        }
        void showData_BEP_CauHinh()
        {
            DataTable tbCauHinh;
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BEP_CAUHINH";
            tbCauHinh = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            
            if (tbCauHinh.Rows.Count > 0)
            {
                Boolean bchkBEP_IN_GIA = true;
                Boolean bchkBEP_IN_SO_HOADON = true;
                Boolean bchkBEP_IN_TEN_BAN = true;
                Boolean bchkBEP_IN_TEN_HANGHOA = true;

                Boolean.TryParse(tbCauHinh.Rows[0]["IN_GIA"] + "", out bchkBEP_IN_GIA);
                Boolean.TryParse(tbCauHinh.Rows[0]["IN_SO_HOADON"] + "", out bchkBEP_IN_SO_HOADON);
                Boolean.TryParse(tbCauHinh.Rows[0]["IN_TEN_BAN"] + "", out bchkBEP_IN_TEN_BAN);
                Boolean.TryParse(tbCauHinh.Rows[0]["IN_TEN_HANGHOA"] + "", out bchkBEP_IN_TEN_HANGHOA);

                chkBEP_IN_GIA.Checked = bchkBEP_IN_GIA;
                chkBEP_IN_SO_HOADON.Checked = bchkBEP_IN_SO_HOADON;
                chkBEP_IN_TEN_BAN.Checked = bchkBEP_IN_TEN_BAN;
                chkBEP_IN_TEN_HANGHOA.Checked = bchkBEP_IN_TEN_HANGHOA;
            }
            else
            {
                chkBEP_IN_GIA.Checked = true;
                chkBEP_IN_SO_HOADON.Checked = true;
                chkBEP_IN_TEN_BAN.Checked = true;
                chkBEP_IN_TEN_HANGHOA.Checked = true;
            }
        }
        void ShowEdit_BEP(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_Bep, _ma); 
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_BEP_MayIn();
        }

        private void btnLuu_BEP_Click(object sender, EventArgs e)
        {
            string sSQL = "UPDATE DM_MAYIN_BEP_CAUHINH "+
                          "SET "+
                          "     IN_GIA = '" + chkBEP_IN_GIA.Checked + "' "+
                          ",    IN_TEN_HANGHOA = '" + chkBEP_IN_TEN_HANGHOA.Checked + "' " +
                          ",    IN_TEN_BAN = '" + chkBEP_IN_TEN_BAN.Checked + "' " +
                          ",    IN_SO_HOADON = '" + chkBEP_IN_SO_HOADON.Checked+ "' "
                          ;

            int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                            new string[] { "@sSQL" }, new object[] { sSQL });
            if (irt >= 0)
                new mh_thongbao("Lưu thành công", 2).ShowDialog();
        }

        private void btnThoat_Bep_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        #endregion

        #region "   Hoa Don"

        private void bton_dautrang_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtHEADER.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtHEADER.Text = s;
        }

        private void bton_cuoitrang_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtFOOTER.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtFOOTER.Text = s;
        }

        private void btnCanh_Tren_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Tren);
            omh_so.ShowDialog();
        }
        void Canh_Tren(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numMARIN_TOP.Value = dc;
                }
            }
        }

        private void btnCanh_Duoi_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Duoi);
            omh_so.ShowDialog();
        }
        void Canh_Duoi(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numMARIN_BOTTOM.Value = dc;
                }
            }
        }


        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //them
            this.ShowEdit_HoaDon("-1");
        }

        private void simpleButton8_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_HoaDon.GetDataRow(gridView_HoaDon.FocusedRowHandle);
            ma = dr["DM_MAYIN_HD_MA"] + "";

            if (ma != "")
            {
                if (new mh_thongbao("Bạn muốn xóa", 4).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_HD WHERE DM_MAYIN_HD_MA=" + ma;
                    int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });

                    this.showData_HoaDon_MayIn();
                }
            }
        }

        private void simpleButton7_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_HoaDon.GetDataRow(gridView_HoaDon.FocusedRowHandle);
            ma = dr["DM_MAYIN_HD_MA"] + "";
            this.ShowEdit_HoaDon(ma);
        }

        private void btnThoat_HoaDon_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        void showData_HoaDon_MayIn()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_HD";

            DataTable tbInHoaDon = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControl_HoaDon.DataSource = tbInHoaDon.Copy();
        }
        void showData_HoaDon_CauHinh()
        {
            DataTable tbDM_MAYIN_HD_CAUHINH;
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_HD_CAUHINH";
            tbDM_MAYIN_HD_CAUHINH = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });

            if (tbDM_MAYIN_HD_CAUHINH.Rows.Count > 0)
            {
                txtLOGO_PATH.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["LOGO_PATH"] + "";

                txtHEADER.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["HEADER"] + "";
                txtFOOTER.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["FOOTER"] + "";

                decimal dcMARIN_TOP = 0;
                decimal.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["MARIN_TOP"] + "", out dcMARIN_TOP);
                numMARIN_TOP.Value = dcMARIN_TOP;

                decimal dcMARIN_BOTTOM = 0;
                decimal.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["MARIN_BOTTOM"] + "", out dcMARIN_BOTTOM);
                numMARIN_BOTTOM.Value = dcMARIN_BOTTOM;

                //
                Boolean bchkPRINT_PRICE = true;
                Boolean bchkPRINT_STORE_NAME = true;

                Boolean bchkPRINT_RECEIPT_TITLE = true;
                Boolean bchkPRINT_PHONE_NUMBER = true;

                Boolean bchkPRINT_STORE_ADDRESS = true;
                Boolean bchkPRINT_ORDER_NO = true;

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_PRICE"] + "", out bchkPRINT_PRICE);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_STORE_NAME"] + "", out bchkPRINT_STORE_NAME);

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_RECEIPT_TITLE"] + "", out bchkPRINT_RECEIPT_TITLE);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_PHONE_NUMBER"] + "", out bchkPRINT_PHONE_NUMBER);

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_STORE_ADDRESS"] + "", out bchkPRINT_STORE_ADDRESS);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_ORDER_NO"] + "", out bchkPRINT_ORDER_NO);

                chkHD_PRINT_PRICE.Checked = bchkPRINT_PRICE;
                chkHD_PRINT_STORE_NAME.Checked = bchkPRINT_STORE_NAME;

                chkHD_PRINT_RECEIPT_TITLE.Checked = bchkPRINT_RECEIPT_TITLE;
                chkHD_PRINT_PHONE_NUMBER.Checked = bchkPRINT_PHONE_NUMBER;

                chkHD_PRINT_STORE_ADDRESS.Checked = bchkPRINT_STORE_ADDRESS;
                chkHD_PRINT_ORDER_NO.Checked = bchkPRINT_ORDER_NO;
                //
                txtTieuDe_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["TITLE"] + "";
                txtSoDienThoai_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["ADDRESS"] + "";
                txtDiaChi_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["PHONE"] + "";
            }
            else
            {
                chkHD_PRINT_PRICE.Checked = true;
                chkHD_PRINT_STORE_NAME.Checked = true;

                chkHD_PRINT_RECEIPT_TITLE.Checked = true;
                chkHD_PRINT_PHONE_NUMBER.Checked = true;

                chkHD_PRINT_STORE_ADDRESS.Checked = true;
                chkHD_PRINT_ORDER_NO.Checked = true;
                //
                txtTieuDe_HD.Text = "";
                txtSoDienThoai_HD.Text = "";
                txtDiaChi_HD.Text = "";
            }
        }
        void ShowEdit_HoaDon(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_HoaDon, _ma);
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_HoaDon_MayIn();
        }

        private void btnLuu_HoaDon_Click(object sender, EventArgs e)
        {
            string sSQL = "UPDATE DM_MAYIN_HD_CAUHINH " +
                          "SET " +
                          "     LOGO_PATH = N'" + txtLOGO_PATH.Text.Trim() + "', " +
                          "     HEADER = N'" + txtHEADER.Text.Trim() + "', " +
                          "     FOOTER = N'" + txtFOOTER.Text.Trim() + "', " +
                          "     MARIN_TOP = " + numMARIN_TOP.Value + ", " +
                          "     MARIN_BOTTOM = " + numMARIN_BOTTOM.Value + ", " +
                          "     PRINT_PRICE = '" + chkHD_PRINT_PRICE.Checked + "', " +
                          "     PRINT_RECEIPT_TITLE = '" + chkHD_PRINT_RECEIPT_TITLE.Checked + "', " +
                          "     PRINT_PHONE_NUMBER = '" + chkHD_PRINT_PHONE_NUMBER.Checked + "', " +
                          "     PRINT_STORE_NAME = '" + chkHD_PRINT_STORE_NAME.Checked + "', " +
                          "     PRINT_STORE_ADDRESS = '" + chkHD_PRINT_STORE_ADDRESS.Checked + "', " +
                          "     PRINT_ORDER_NO = '" + chkHD_PRINT_ORDER_NO.Checked + "', " +
                          "     TITLE = N'" + txtTieuDe_HD.Text.Trim() + "', " +
                          "     [ADDRESS] = N'" + txtDiaChi_HD.Text + "', " +
                          "     PHONE = N'" + txtSoDienThoai_HD.Text + "' "
                          ;

            int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                            new string[] { "@sSQL" }, new object[] { sSQL });
            if (irt >= 0)
                new mh_thongbao("Lưu thành công", 2).ShowDialog();
        }
        #endregion

        #region "   Bien Nhan"

        private void bton_dautrang_BN_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtHEADER_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtHEADER_BN.Text = s;
        }

        private void bton_cuoitrang_BN_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtFOOTER_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtFOOTER_BN.Text = s;
        }

        private void btnCanh_Tren_BN_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Tren_BN);
            omh_so.ShowDialog();
        }
        void Canh_Tren_BN(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numBN_MARIN_TOP.Value = dc;
                }
            }
        }

        private void btnCanh_Duoi_BN_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Duoi_BN);
            omh_so.ShowDialog();
        }
        void Canh_Duoi_BN(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numBN_MARIN_BOTTOM.Value = dc;
                }
            }
        }


        private void btnBN_Them_Click(object sender, EventArgs e)
        {
            //them
            this.ShowEdit_BIENNHAN("-1");
        }

        private void btnBN_Xoa_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_biennhan.GetDataRow(gridView_biennhan.FocusedRowHandle);
            ma = dr["DM_MAYIN_DM_MAYIN_BIENNHAN_MA"] + "";

            if (ma != "")
            {
                if (new mh_thongbao("Bạn muốn xóa", 4).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_BIENNHAN WHERE DM_MAYIN_BIENNHAN_MA=" + ma;
                    int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });

                    this.showData_BIENNHAN_MayIn();
                }
            }
        }

        private void btnBN_Sua_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_biennhan.GetDataRow(gridView_biennhan.FocusedRowHandle);
            ma = dr["DM_MAYIN_BIENNHAN_MA"] + "";
            this.ShowEdit_BIENNHAN(ma);
        }

        private void btnThoat_BIENNHAN_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        void showData_BIENNHAN_MayIn()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BIENNHAN";

            DataTable tbInBN = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControl_BienNhan.DataSource = tbInBN.Copy();
        }
        void showData_BIENNHAN_CauHinh()
        {
            DataTable tbDM_MAYIN_BIENNHAN_CAUHINH;
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BIENNHAN_CAUHINH";
            tbDM_MAYIN_BIENNHAN_CAUHINH = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });

            if (tbDM_MAYIN_BIENNHAN_CAUHINH.Rows.Count > 0)
            {
                txtLOGO_PATH_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["LOGO_PATH"] + "";
                txtHEADER_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["HEADER"] + "";
                txtFOOTER_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["FOOTER"] + "";

                decimal dcMARIN_TOP = 0;
                decimal.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["MARIN_TOP"] + "", out dcMARIN_TOP);
                numBN_MARIN_TOP.Value = dcMARIN_TOP;

                decimal dcMARIN_BOTTOM = 0;
                decimal.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["MARIN_BOTTOM"] + "", out dcMARIN_BOTTOM);
                numBN_MARIN_BOTTOM.Value = dcMARIN_BOTTOM;

                //
                Boolean bchkPRINT_PRICE = true;
                Boolean bchkPRINT_STORE_NAME = true;

                Boolean bchkPRINT_RECEIPT_TITLE = true;
                Boolean bchkPRINT_PHONE_NUMBER = true;

                Boolean bchkPRINT_STORE_ADDRESS = true;
                Boolean bchkPRINT_ORDER_NO = true;

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_PRICE"] + "", out bchkPRINT_PRICE);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_STORE_NAME"] + "", out bchkPRINT_STORE_NAME);

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_RECEIPT_TITLE"] + "", out bchkPRINT_RECEIPT_TITLE);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_PHONE_NUMBER"] + "", out bchkPRINT_PHONE_NUMBER);

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_STORE_ADDRESS"] + "", out bchkPRINT_STORE_ADDRESS);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_ORDER_NO"] + "", out bchkPRINT_ORDER_NO);

                chkBN_PRINT_PRICE.Checked = bchkPRINT_PRICE;
                chkBN_PRINT_STORE_NAME.Checked = bchkPRINT_STORE_NAME;

                chkBN_PRINT_RECEIPT_TITLE.Checked = bchkPRINT_RECEIPT_TITLE;
                chkBN_PRINT_PHONE_NUMBER.Checked = bchkPRINT_PHONE_NUMBER;

                chkBN_PRINT_STORE_ADDRESS.Checked = bchkPRINT_STORE_ADDRESS;
                chkBN_PRINT_ORDER_NO.Checked = bchkPRINT_ORDER_NO;
                //
                txtTieuDe_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["TITLE"] + "";
                txtSoDienThoai_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["ADDRESS"] + "";
                txtDiaChi_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PHONE"] + "";
            }
            else
            {
                chkBN_PRINT_PRICE.Checked = true;
                chkBN_PRINT_STORE_NAME.Checked = true;

                chkBN_PRINT_RECEIPT_TITLE.Checked = true;
                chkBN_PRINT_PHONE_NUMBER.Checked = true;

                chkBN_PRINT_STORE_ADDRESS.Checked = true;
                chkBN_PRINT_ORDER_NO.Checked = true;
                //
                txtDiaChi_BN.Text = "";
                txtTieuDe_BN.Text = "";
                txtSoDienThoai_BN.Text = "";
            }
        }
        void ShowEdit_BIENNHAN(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_BienNhan, _ma);
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_BIENNHAN_MayIn();
        }

        private void btnLuu_BN_Click(object sender, EventArgs e)
        {
            string sSQL = "UPDATE DM_MAYIN_BIENNHAN_CAUHINH " +
                          "SET " +
                          "     LOGO_PATH = N'" + txtLOGO_PATH_BN.Text.Trim() + "', " +
                          "     HEADER = N'" + txtHEADER_BN.Text.Trim() + "', " +
                          "     FOOTER = N'" + txtFOOTER_BN.Text.Trim() + "', " +
                          "     MARIN_TOP = " + numBN_MARIN_TOP.Value + ", " +
                          "     MARIN_BOTTOM = " + numBN_MARIN_BOTTOM.Value + ", " +
                          "     PRINT_PRICE = '" + chkBN_PRINT_PRICE.Checked + "', " +
                          "     PRINT_RECEIPT_TITLE = '" + chkBN_PRINT_RECEIPT_TITLE.Checked + "', " +
                          "     PRINT_PHONE_NUMBER = '" + chkBN_PRINT_PHONE_NUMBER.Checked + "', " +
                          "     PRINT_STORE_NAME = '" + chkBN_PRINT_STORE_NAME.Checked + "', " +
                          "     PRINT_STORE_ADDRESS = '" + chkBN_PRINT_STORE_ADDRESS.Checked + "', " +
                          "     PRINT_ORDER_NO = '" + chkBN_PRINT_ORDER_NO.Checked + "', " +
                          "     TITLE = N'" + txtTieuDe_BN.Text.Trim() + "', " +
                          "     [ADDRESS] = N'" + txtDiaChi_BN.Text + "', " +
                          "     PHONE = N'" + txtSoDienThoai_BN.Text + "' "
                          ;

            int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                            new string[] { "@sSQL" }, new object[] { sSQL });
            if (irt >= 0)
                new mh_thongbao("Lưu thành công", 2).ShowDialog();
        }
        #endregion

        private void btnLuuNhommayIn_Click(object sender, EventArgs e)
        {
            string sDM_MAYIN_BEP_MA = "";

            DataRow dr1 = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            if (dr1 != null)
            {
                sDM_MAYIN_BEP_MA = dr1["DM_MAYIN_BEP_MA"] + "";
            }
            thuvien othuvien = new thuvien();
            foreach (DataRow dr in tbInBep_In.Rows)
            {
                DataRowState sState = dr.RowState;

                object sMa = sDM_MAYIN_BEP_MA;

                string och = dr["chon"] + "";
                if (och + "" == "False")
                {
                    och = och + "";
                    sMa = "0";
                }
                ///
                if (sState == DataRowState.Modified)
                {
                    string sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = " + sMa + " WHERE OBJID LIKE '" + dr["OBJID"] + "' ";
                    othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL"}, new object[] { sSQL});
                }
            }
        }
        DataTable tbInBep_In = null;
        private void gridView_Bep_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            string sDM_MAYIN_BEP_MA = "";

            DataRow dr = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            if (dr != null)
            {
                sDM_MAYIN_BEP_MA = dr["DM_MAYIN_BEP_MA"] + "";
                tbInBep_In = new thuvien().SP_SelectDataTable("sp_DM_MAYIN_BEP",
                                                                    new string[] { "@flag", "@DM_MAYIN_BEP_MA" },
                                                                    new object[] { 5, sDM_MAYIN_BEP_MA });
                gridControl_Bep_In.DataSource = tbInBep_In;
            }
        }

        private void simpleButton17_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtTieuDe_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtTieuDe_HD.Text = s;
        }

        private void simpleButton13_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtDiaChi_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtDiaChi_HD.Text = s;
        }

        private void simpleButton12_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtSoDienThoai_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtSoDienThoai_HD.Text = s;
        }

        private void simpleButton16_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtTieuDe_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtTieuDe_BN.Text = s;
        }

        private void simpleButton15_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtDiaChi_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtDiaChi_BN.Text = s;
        }

        private void simpleButton14_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtSoDienThoai_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtSoDienThoai_BN.Text = s;
        }
        
    }
}
